﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using C1.Web.Wijmo.Controls.C1GridView;

namespace weba
{
    public partial class itemedit : System.Web.UI.Page
    {
   private     static int hid;
   public static string grdid;
        sjklqDataContext sj = new sjklqDataContext();
        public static List<string> ids = new List<string>();
        public static List<string> prtids = new List<string>();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                ids.Clear();
                    prtids.Clear();
                 //   System.Web.UI.ScriptManager.RegisterStartupScript(this.CheckBox2, this.GetType(), "alert", "<script type='text/javascript' src='Scripts/jquery-1.8.2.min.js'></script><script type='text/javascript'> $('#CheckBox2').click(function () { $(':checkbox').prop('checked', false);});</script>",false);
            }
        }

        protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            Image1.Visible = true;
            Image1.ImageUrl = "Images/" + DropDownList1.SelectedValue.ToString();
        }

        protected void Button4_Click(object sender, EventArgs e)
        {
            //this.C1Dialog1.Visible = true;
            this.C1Dialog1.Visible = true;
        }

        protected void Button5_Click(object sender, EventArgs e)
        {
        //Image ti =   (Image)DataList1.SelectedItem.FindControl("Image2");
        
        }

        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {
           ImageButton mt = sender as ImageButton;
           // DropDownList1.SelectedIndex = DropDownList1.Items.IndexOf(DropDownList1.Items.FindByValue(mt.DescriptionUrl.ToString()));
            this.C1Dialog1.Visible = false;
            //this.DataList1.Visible = false;
           // int ai = hid;
          //  string pichm = this.C1GridView1.DataKeys[ai].ToString();
            var xiugaipic = sj.Item.Single(h => h.id == grdid);
            xiugaipic.imageUrl = mt.DescriptionUrl.ToString();
            sj.SubmitChanges();
            C1GridView1.DataBind();
        }

        protected void ImageButton3_Click(object sender, ImageClickEventArgs e)
        {
            
            this.C1Dialog1.Visible = true;
            
        }
        protected void bindcklst()
        {

        }

        protected void CheckBoxList1_DataBound(object sender, EventArgs e)
        {

        }

        protected void DataList2_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        protected void Button6_Click(object sender, EventArgs e)
        {
            this.C1Dialog1.Visible = false;
        }

        protected void C1GridView1_SelectedIndexChanged(object sender, EventArgs e)
        {
           
        }

        protected void C1GridView1_SelectedIndexChanging(object sender, C1.Web.Wijmo.Controls.C1GridView.C1GridViewSelectEventArgs e)
        {
            hid = e.NewSelectedIndex;
        }

        protected void C1GridView1_RowCommand(object sender, C1.Web.Wijmo.Controls.C1GridView.C1GridViewCommandEventArgs e)
        {
            if (e.CommandName == "getpic")
            {
                grdid = e.CommandArgument.ToString();
            }
        }

        protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
        {
            CheckBox cka = sender as CheckBox;
              
            if (cka.Checked== true)
            {
                int a = (cka.NamingContainer as C1GridViewRow).RowIndex;
          ids.Add(C1GridView1.DataKeys[a].Value.ToString());
            }
            if (cka.Checked == false)
            {
                int a = (cka.NamingContainer as C1GridViewRow).RowIndex;
                ids.Remove(C1GridView1.DataKeys[a].Value.ToString());
            }
            Label1.Text = ids.Count.ToString();
        }

        protected void CheckBoxList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            
            prtids.Clear();
            for (int i = 0; i < CheckBoxList1.Items.Count; i++)
            {
                if (CheckBoxList1.Items[i].Selected)
                {
                    prtids.Add(CheckBoxList1.Items[i].Value.ToString());
                }
               
            }
            Label2.Text = prtids.Count.ToString();
        }

        protected void Button5_Click1(object sender, EventArgs e)
        {
           
            foreach (string sa in ids)
            {
                foreach (string sb in prtids)
                {
                    sj.addctz(sa, sb);

                }
            }
            sj.SubmitChanges();
            Label1.Text = "已添加" + ids.Count+"产品";
            Label2.Text = "到" + prtids.Count + "类目";
        }

        protected void Button6_Click1(object sender, EventArgs e)
        {
            for (int i = 0; i < CheckBoxList1.Items.Count; i++)
            {
                CheckBoxList1.Items[i].Selected = false;
              

            }
            for (int i = 0; i < C1GridView1.Rows.Count; i++)
            {
                CheckBox bk = C1GridView1.Rows[i].FindControl("CheckBox1") as CheckBox;
                bk.Checked = false;
            }
            ids.Clear();
            prtids.Clear();
 Label1.Text="";
             Label2.Text="";
        }
    }
}